/*
 * Copyright (C) 2006-2015
 * 版权所有者为北京捷越联合信息咨询有限公司。本系统是商用软件,未经授权擅自复制或传播本程序的部分或全部将是非法的。
 * @title: TbjBusinessClient.java
 * @package com.jy.modules.cims.component.tbj
 * @author zhaox
 * @date 2015-9-6 上午11:05:08
 * @version v1.00
 * @description: TODO(用一句话描述该文件做什么)
 */

package com.jy.modules.cims.component.tbj;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.data.dto.inter.tbj.TBJMessage;
import com.jy.modules.cims.data.dto.inter.tbj.TBJRequest;
import com.jy.modules.cims.data.dto.inter.tbj.TBJResponse;
import com.jy.modules.cims.data.dto.inter.tbj.fk.LoanResultDto;
import com.jy.modules.cims.data.dto.inter.tbj.jj.AbortDTO;
import com.jy.modules.cims.data.dto.inter.tbj.jj.AttachContent;
import com.jy.modules.cims.data.dto.inter.tbj.jj.JjDTO;
import com.jy.modules.cims.data.dto.inter.tbj.jj.NoticeDTO;
import com.jy.modules.cims.data.dto.inter.tbj.sd.LoanSendDTO;
import com.jy.modules.cims.data.dto.inter.tbj.sh.AuditResultDto;
import com.jy.modules.cims.interact.TBJClient;

/**
 * @classname: TbjBusinessClient
 * @description: TODO(这里用一句话描述这个类的作用)
 */
@Service("com.jy.modules.cims.component.tbj.TBJBusinessClient")
public class TBJBusinessClient implements ITBJBusinessClient {

    @Autowired
    @Qualifier("com.jy.modules.cims.interact.TBJClient")
    public TBJClient tBJSendClient;

    /**
     * 进件推送
     * 
     * @title: addConsume
     * @author
     * @description:
     * @date 2015-9-6 下午2:10:22
     * @param jjDTO
     * @throws
     */
    @Override
    public TBJResponse addConsume(JjDTO jjDTO) {
        TBJRequest tbjRequest = new TBJRequest();
        tbjRequest.setMethod("tbj.loan.p2p.add");
        tbjRequest.setContent(jjDTO);
        tbjRequest.setClazz(TBJMessage.class);
        TBJResponse tBJResponse = tBJSendClient.sendToTbj(tbjRequest);
        return tBJResponse;
    }

    /**
     * 推送完成通知
     * 
     * @title: notice
     * @author
     * @description:
     * @date 2015-9-6 下午2:12:01
     * @param notice
     * @throws
     */
    @Override
    public TBJMessage notice(NoticeDTO notice) {
        TBJRequest tbjRequest = new TBJRequest();
        tbjRequest.setMethod("tbj.loan.p2p.notice");
        tbjRequest.setContent(notice);
        tbjRequest.setClazz(TBJMessage.class);
        TBJResponse tBJResponse = tBJSendClient.sendToTbj(tbjRequest);
        return (TBJMessage) tBJResponse.getData();
    }

    /**
     * 发送附件信息
     * 
     * @title: addAttach
     * @author
     * @description:
     * @date 2015-9-6 下午2:45:51
     * @throws
     */
    @Override
    public TBJMessage addAttach(AttachContent attachContent) {
        TBJRequest tbjRequest = new TBJRequest();
        tbjRequest.setMethod("tbj.loan.attach.add");
        tbjRequest.setContent(attachContent);
        tbjRequest.setClazz(TBJMessage.class);
        attachContent.setStreamId(String.valueOf(System.currentTimeMillis()));
        TBJResponse tBJResponse = tBJSendClient.sendToTbj(tbjRequest);
        return (TBJMessage) tBJResponse.getData();
    }

    /**
     * 审核结果查询
     * 
     * @title: searchAudit
     * @author
     * @description:
     * @date 2015-9-6 下午2:46:14
     * @return
     * @throws
     */
    @Override
    public TBJResponse searchAudit(String id) {
        TBJRequest tbjRequest = new TBJRequest();
        tbjRequest.setMethod("tbj.loan.audit.search");
        tbjRequest.setContent(id);
        tbjRequest.setClazz(AuditResultDto.class);
        TBJResponse tBJResponse = tBJSendClient.sendToTbj(tbjRequest);
        return tBJResponse;
    }

    /**
     * 放款结果查询
     * 
     * @title: searchLoan
     * @author
     * @description:
     * @date 2015-9-6 下午2:46:16
     * @return
     * @throws
     */
    @Override
    public TBJResponse searchLoan(String id) {
        TBJRequest tbjRequest = new TBJRequest();
        tbjRequest.setMethod("tbj.loan.loan.search");
        tbjRequest.setContent(id);
        tbjRequest.setClazz(LoanResultDto.class);
        TBJResponse tBJResponse = tBJSendClient.sendToTbj(tbjRequest);
        return tBJResponse;
    }

    /**
     * 发送放款信息
     * @Description 
     * @param jjDTO
     * @return   
     * TBJResponse  
     * @throws
     * @author zhangmi
     * @date 2015-10-8
     */
    @Override
    public TBJResponse addLoan(List<LoanSendDTO> list) {
        TBJRequest tbjRequest = new TBJRequest();
        tbjRequest.setMethod("tbj.loan.lend");
        tbjRequest.setContent(list);
        tbjRequest.setClazz(TBJMessage.class);
        tbjRequest.setType(CimsConstant.TBJ_SEND_TYPE_LIST);//发送list集合，如果为空发送单个
        TBJResponse tBJResponse = tBJSendClient.sendToTbj(tbjRequest);
        return tBJResponse;
    }
    
    @Override
    public TBJResponse abort(AbortDTO abortDto) {
        TBJRequest tbjRequest = new TBJRequest();
        tbjRequest.setMethod("tbj.loan.abort");
        tbjRequest.setContent(abortDto);
        tbjRequest.setClazz(TBJMessage.class);
        TBJResponse tBJResponse = tBJSendClient.sendToTbj(tbjRequest);
        return tBJResponse;
    }
   
}
